package com.xht.controller;

import com.xht.domain.ResponseResult;
import com.xht.domain.entity.User;
import com.xht.enums.AppHttpCodeEnum;
import com.xht.exception.SystemExceptin;
import com.xht.service.BlogLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BlogLoginController {

    @Autowired
    private BlogLoginService blogLoginService;


    /**
     * 登录校验
     */
    @PostMapping("/login")
    public ResponseResult login(@RequestBody User user) {
        //一些基本校验
        if (!StringUtils.hasText(user.getUserName())) {
            //提示 需要传 用户名
            throw new SystemExceptin(AppHttpCodeEnum.REQUIRE_USERNAME);
        }
        return blogLoginService.login(user);
    }

    /**
     * 退出登录
     */
    @PostMapping("/logout")
    public ResponseResult logout() {

        return blogLoginService.logout();
    }

}
